package com.example.PDFdemo.pdf;

import com.example.PDFdemo.pdftest.PDFModel;
import com.itextpdf.text.*;
import com.itextpdf.text.pdf.*;

import java.io.FileOutputStream;
import java.util.List;

public class PDFTool {

    public static void addText(String oldFilePath, String newFilePath, List<PDFModel> models) throws Exception {
        //创建Document对象
        Document document = new Document();
        //创建PdfReader对象
        PdfReader reader = new PdfReader(oldFilePath);
        //创建FileOutputStream对象
        FileOutputStream stream = new FileOutputStream(newFilePath);
        //创建PdfWriter对象
        PdfWriter writer = PdfWriter.getInstance(document, stream);
        //创建PdfContentByte对象
        PdfContentByte pdfContentByte = new PdfContentByte(writer);
        //打开编辑
        document.open();
        //循环添加文本
        for (PDFModel model : models) {
            //设置字体
            String fontPath = "static/" + model.getFontName() + ".ttf";
            BaseFont basefont = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font font = new Font(basefont, model.getFontSize());
            //创建一个块对象
            Chunk chunk = new Chunk(model.getContext(), font);
        }
    }

}
